<template>
  <div style="width:100%;height:100%">
      <div style="text-align:right;width:100%">
        <el-button type="primary" icon="el-icon-edit" @click="saveLuckySheet">保存</el-button>
        <el-button type="primary" icon="el-icon-download" @click="exportLuckySheet">导出</el-button>
      </div>
    <div id="luckysheet"
         style="margin:0px;padding:0px;position:absolute;width:100%;height:100%;left: 0px;top: 0px;"
    ></div>

  </div>

</template>
<script>
import { saveLuckySheet,getReport} from "@/api/system/report";
  export default {
  name: "TemplateR",
    components: {},
    props: [],
    data() {return {
      option : {
          container :"luckysheet",
          lang: "zh",
          showsheetbar: true,
          showinfobar: true
        }
    }},
    computed: {},
    watch: {},
    created() {
      this.getLuckySheetData()
    },
    beforeDestroy(){
      luckysheet.destroy()
    },
    mounted() {
      },
    methods: {
      createLuckySheet(){
      //获取luckysheet初始化数据
      luckysheet.destroy()
      console.log("this.option",this.option)
      luckysheet.create(this.option)
      },
      getLuckySheetData(){
        getReport(this.$route.params.pkid).then(res=>{
          this.option.data =res.data.reportData
          this.createLuckySheet()
        })
      },
      saveLuckySheet(){
        let excel = luckysheet.getAllSheets();
        for(var i in excel) excel[i].data = undefined
        const param = {
          pkid : this.$route.params.pkid,
          data : JSON.stringify(excel),
        }
        saveLuckySheet(param).then( res =>{
          if(res.code ==200){
            this.$modal.msgSuccess("保存成功");

          }
        })
      },
      exportLuckySheet(){
      console.log(LuckyExcel,"LuckyExcel")
     // let excel = luckysheet.getAllSheets();
     // LuckyExcel.transformLuckyToExceljs(excel, (data) => {
     //     console.log('导出成功---->>', data)
     // }, (e) => {
     //     console.log('导出失败---->>', e)
     // })
      }
    }
  }

</script>
<style>
  #luckysheet{
  width:100%!important;
  height:calc(100% - 25px)!important;
  position:relative!important;
  z-index:10

  }
</style>
